const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
const util = require('../../utils/util.js');

Page({
  data: {
    isfixed:false,
    listsheight:20,
    cate:'联结',
    iscate:false,
    categoryList:[],
    productList:[],
    userInfo:'',
    tabList:[
      {'img':"https://ht.himantrip.com/miniStatic/gerenxinxi@2x.png",'text':"个人信息"},
      {'img':"https://ht.himantrip.com/miniStatic/qian@2x.png",'text':"我的邀请"},
      {'img':"https://ht.himantrip.com/miniStatic/xinxi@2x.png",'text':"意见反馈"},
      {'img':"https://ht.himantrip.com/miniStatic/hao@2x.png",'text':"关于我们"},
      // {'img':"https://ht.himantrip.com/miniStatic/ke@2x.png",'text':"客服电话"}
    ],
    contact:"",
    bottomLift: 0,
    user:""
  },
  onLoad() {
    let {bottomLift} = app.globalData
    if(bottomLift>=0){
      app.getDeviceSize().then(res => {
        const {bottomLift} = res
        this.setData({
          bottomLift
        })
      })
    }else{
      this.setData({
        bottomLift
      })
    }

    this.appinfo()
    this.getUser()
  },
  onShow(){
    if(!wx.getStorageSync('userInfo')){
      app.ToLogin()
    }else{
      var obj=wx.getStorageSync('userInfo');
      var list=obj.createTime.split(' ')[0].split('-');
      obj.createTime=list[0]+'年'+list[1]+'月'+list[2]+'日';
      this.setData({
        userInfo:obj
      })
    }

    this.getUser();

  },
  // ToLogin(delta) {
  //   var that=this;
  //   wx.showModal({
  //     title: '提示',
  //     content: '是否授权登录?',
  //     success(res) {
  //       // console.log(res)
  //       if (res.confirm) {
  //         wx.getUserProfile({
  //           desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
  //           success: (res) => {
  //             if(res.userInfo){
  //               // console.log(res)
  //               Controller.getinfo({'token':res.signature}).then((msg)=>{
  //                 console.log(msg)
  //               })
  //             }
  //           },
  //           fail:(res)=>{
  //             wx.switchTab({
  //               url: '/pages/index/index'
  //             })
  //           }
  //         })
  //       } else if (res.cancel) {
  //           wx.switchTab({
  //             url: '/pages/index/index'
  //           })
  //         console.log('用户点击取消')
  //       }
  //     }
  //   })
  // },
  toLink(tap){

    if(tap.currentTarget.dataset.text =="个人信息"){
      wx.navigateTo({
        url: '../myInfo/myInfo',
      })
    }else if(tap.currentTarget.dataset.text =="关于我们"){
      wx.navigateTo({
        url: '../about/about',
      })
    }else if(tap.currentTarget.dataset.text =="意见反馈"){
      wx.navigateTo({
        url: '../feedback/feedback',
      })
    }else if(tap.currentTarget.dataset.text =="我的邀请"){
        var a=this.data.user.role.userType;
        if(a == 0||a == 4 ||a == 7){
          wx.navigateTo({
            url: '../invitation/users/users',
          })
          
        }else{
          wx.navigateTo({
            url: '../invitation/user/user',
          })
        }
    }


  },
  addPhone(){
    wx.makePhoneCall({
      phoneNumber:this.data.contact
    }).catch((e) => {
       console.log(e)  
    })
  
  },
  appinfo(){  //appinfo
    Controller.appinfo({key:"key-online-contact"}).then((res)=>{
        this.setData({
          contact:res.data.baseData.content
        })
    })
  },
  getUser(){
    Controller.info({}).then((res)=>{
        this.setData({
          user:res.data.baseData
        })
    })
  },
  onShareAppMessage: function (e) {
    
  },
  onShareTimeline: function(res){
    
  },
})